package states.designer
{
	import components.Background;
	
	import components.Circle;
	import components.Component;
	import components.Link;
	
	import oboe.core.Controller;
	import oboe.utils.japi;
	
	public class DesignerPerspective extends Controller
	{
		public function DesignerPerspective()
		{
			super( );
			this.addChild( new Background( DesignerCircle ) );
			this.addChild( new LinkEditor() );
		}
		
		[slot] public function save():void
		{
			var data:Object = {
				nodes : {},
				links : {}
			};
			
			this.signalDown("getSaveData", data);
			japi.save( data, function( ret:Object ):void{
				trace( ret );
				signalDown("saveComplete");
			} );
		}
		
		[slot] public function addElement( el:Controller ):void
		{
			this.addChild( el );
		}

		[slot(alias=dblClickDesignerLink)] public function altClickLink( c:Link ):void
		{
			this.signalDown("editLink", c);
		}
		
		[slot] public function dblClickDesignerCircle( c:Circle ):void
		{
			this.signalUp("editLayout", c.getUpdatedData());
		}
		
		[slot] public function altClickCircle( c:Circle ):void
		{
			c.startInputMode();
		}

		[slot] public function ctrlClickDesignerCircleWithSelection( target:Circle, selection:Component ):void
		{
			if( !(selection is Circle) ) return;
			selection.message("linkTo", target, new DesignerLink( Circle(selection), target ) );
			target.setSelected(true);
		}
		
		[slot] public function altClickDesignerCircleWithSelection( target:Circle, selection:Component ):void
		{
			if( !selection is Circle ) return;
			selection.message("linkTo", target, new DesignerLink( Circle(selection), target ) );
		}
	}
}
